package com.lsp.test.blockingqueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class PrintProcessor extends Thread implements IRequestProcessor {

    protected  IRequestProcessor nextProcessor;

    private BlockingQueue<Request> requests = new LinkedBlockingQueue<>();

    public PrintProcessor(IRequestProcessor nextProcessor) {
        this.nextProcessor = nextProcessor;
    }

    @Override
    public void processRequest(Request request) {
        requests.add(request);
    }

    @Override
    public void run() {
        while (true){
            try {
                Request take = requests.take();
                System.out.println("PrintProcessor"+take);
                if(null != nextProcessor){
                    nextProcessor.processRequest(take);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }
}
